import request, { scope } from '../../utils/request';

const productUrl = scope('user/product');

/**
 * 商品信息的查询
 * @param {*} page
 * @param {*} size
 * @param {*} options
 * @returns
 */
export const getProduct = (page = 1, size = 10, options = {}) => {
  console.log("options")
  console.log(options)
  /**
   * {
   *  "id": 3, // 非必须条件
   *  "categoryId": "1", // 非必须条件
   *  "shopId": "1", // 非必须条件
   *  "name": "商品名称", // 非必须条件
   *  "seq": "商品序号", // 非必须条件
   *  "status": "1", // 非必须条件
   *  "sellCount": 500 // 非必须条件
   * }
   */
  return request({
    url: productUrl(`findProduct/${page}/${size}`),
    method: Object.keys(options).length > 0 ? 'post' : 'get',
    data: { ...options },
  });
};

/**
 * 添加商品
 * @param {*} product
 * @returns
 */
export const addProduct = (product) => {
  /**
   * {
   *   "categoryId": 1,
   *   "shopId": 1,
   *   "name": "wdafdaf",
   *   "sellingPoint": "hdoasfj",
   *   "mainImgUrl": "dhgosidgh",
   *   "imgUrls": "sdljghshdg",
   *   "videoUrl": "skdhfosg",
   *   "price": 20.0,
   *   "marketPriceFee": 3.0, // 非必填
   *   "stock": 50,
   *   "detail": "khflsdgbl"
   * }
   */
  return request({
    url: productUrl('addProduct'),
    method: 'post',
    data: { ...product },
  });
};

/**
 * 修改商品
 * @param {*} product
 * @returns
 */
export const updateProduct = (product) => {
  return request({
    url: productUrl('update'),
    method: 'post',
    data: { ...product },
  });
};

export const getProductByEs = (name) => {
  return request({
    url: productUrl('es'),
    method: 'post',
    data: {name}
  });
};
